package com.ruoyi.web.controller.fuwu;

import java.util.List;

import com.ruoyi.system.service.IJiuyuanService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Jiuyuan;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 救援服务 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Controller
@RequestMapping("/system/jiuyuan")
public class JiuyuanController extends BaseController
{
    private String prefix = "system/jiuyuan";
	
	@Autowired
	private IJiuyuanService jiuyuanService;
	
	@RequiresPermissions("system:jiuyuan:view")
	@GetMapping()
	public String jiuyuan()
	{
	    return prefix + "/jiuyuan";
	}
	
	/**
	 * 查询救援服务列表
	 */
	@RequiresPermissions("system:jiuyuan:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Jiuyuan jiuyuan)
	{
		startPage();
        List<Jiuyuan> list = jiuyuanService.selectJiuyuanList(jiuyuan);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出救援服务列表
	 */
	@RequiresPermissions("system:jiuyuan:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Jiuyuan jiuyuan)
    {
    	List<Jiuyuan> list = jiuyuanService.selectJiuyuanList(jiuyuan);
        ExcelUtil<Jiuyuan> util = new ExcelUtil<Jiuyuan>(Jiuyuan.class);
        return util.exportExcel(list, "jiuyuan");
    }
	
	/**
	 * 新增救援服务
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存救援服务
	 */
	@RequiresPermissions("system:jiuyuan:add")
	@Log(title = "救援服务", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Jiuyuan jiuyuan)
	{		
		return toAjax(jiuyuanService.insertJiuyuan(jiuyuan));
	}

	/**
	 * 修改救援服务
	 */
	@GetMapping("/edit/{jiuyuanId}")
	public String edit(@PathVariable("jiuyuanId") Integer jiuyuanId, ModelMap mmap)
	{
		Jiuyuan jiuyuan = jiuyuanService.selectJiuyuanById(jiuyuanId);
		mmap.put("jiuyuan", jiuyuan);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存救援服务
	 */
	@RequiresPermissions("system:jiuyuan:edit")
	@Log(title = "救援服务", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Jiuyuan jiuyuan)
	{		
		return toAjax(jiuyuanService.updateJiuyuan(jiuyuan));
	}
	
	/**
	 * 删除救援服务
	 */
	@RequiresPermissions("system:jiuyuan:remove")
	@Log(title = "救援服务", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(jiuyuanService.deleteJiuyuanByIds(ids));
	}

	/**
	 * 修改救援状态
	 * @param jiuyuan
	 * @return
	 */
	@Log(title = "救援服务", businessType = BusinessType.UPDATE)
	@RequiresPermissions("system:jiuyuan:edit")
	@PostMapping("/changeStatus")
	@ResponseBody
	public AjaxResult changeStatus(Jiuyuan jiuyuan)
	{
		return toAjax(jiuyuanService.updateJiuyuan(jiuyuan));
	}
	
}
